package com.it.App.exception;


import com.it.App.vo.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.ExpiredCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @ClassName:GlobalException
 */
@Slf4j
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(value = UnauthorizedException.class)
    public Response<?> handler(UnauthorizedException e) {
        log.error("运行时异常：----------------{}", e.getMessage());
        return Response.error(402,"无权限操作");
    }

    @ExceptionHandler(value = ExpiredCredentialsException.class)
    public Response<?> handler(ExpiredCredentialsException e) {
        log.error("运行时异常：----------------{}", e.getMessage());
        return Response.error(401,"登录已过期，请重新登录");
    }


    @ExceptionHandler(value = UnauthenticatedException.class)
    public Response<?> handler(UnauthenticatedException e) {
        log.error("运行时异常：----------------{}", e);
        return Response.error(401,"未登录");
    }

    @ExceptionHandler(value = UnknownAccountException.class)
    public Response<?> handler(UnknownAccountException e) {
        log.error("运行时异常：----------------{}", e);
        return Response.error(402,"未登录123");
    }
}
